<template>
  <div>
    <el-dialog title="提示" :visible.sync="deleteDialogVisible" width="30%" @close="onClose">
      <span>确定要删除吗？删除后将不可以恢复</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {deleteUser} from '@/api/users.js'
export default {
  name: "DeleteUser",
  props:{
    deleteVisible:{
      type: Boolean,
      default: false
    },
    userId:{
      type:Number,
      default: 0
    }
  },
  data(){
    return {
      deleteDialogVisible: false
    }
  },
  watch:{
    deleteVisible(){
      this.deleteDialogVisible = this.deleteVisible
    }
  },
  methods: {
    onClose(){
      this.$emit('changDeleteShow',false)
    },
    cancel(){
      this.$emit('changDeleteShow',false)
    },
    confirm(){
      this.$emit('changDeleteShow',false)
      this.delete(this.userId);
    },
    async delete(userId){
        const {data : res} = await deleteUser(userId)

        if(res.code == 200){
          this.$notify({
            title: '删除成功',
            message: '用户已删除',
            type: 'success'
          });
          this.$emit('changDeleteShow',false)
        }else{
          this.$messagse.error("用户信息更新失败"+res.message);
        }
    }

  },
};
</script>
<style>
</style>